package com.homegoods.designer.presenter;

import android.support.annotation.IntDef;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.homegoods.classify.model.Constant;
import com.homegoods.designer.DesignerApiUtils;
import com.homegoods.designer.model.DesignerModel;
import com.homegoods.designer.ui.view.IDesignView;
import com.kedll.library.mvp.AbstractRefreshPresenter;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Random;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


/**
 * @author QiQi
 */
public class DesignerPresenter extends AbstractRefreshPresenter<IDesignView> {

    public final static int C_AREA = 0;
    public final static int C_TYPE = 1;
    public static final int C_PRICE = 2;
    public static final int C_ALL = 3;
    Random random = new Random();
    private String condition;
    private String region = "";
    private String type = "";
    private String offer = "";


    public DesignerPresenter(IDesignView view) {
        super(view);
    }

    public void setCondition(String condition) {
        this.condition = condition;

        refreshData();
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        DesignerApiUtils.getDesignerList(region, type, offer, subModelList -> {
            List<DesignerModel> model = JSON.parseArray(subModelList.getItems(), DesignerModel.class);
            parserData(isLoadMore, model);
        }, throwable -> {

        });
//        addSubscription(Observable.range(0, 10)
//                .map(integer -> {
//                    DesignerModel model = new DesignerModel();
//                    model.setName("王鹏");
//                    model.setExp("3年设计经验");
//                    model.setHeadUrl(Constant.TEST_IMG_URL + random.nextInt(100));
//                    model.setLevel(random.nextInt(5));
//                    model.setPrice("200-300");
//                    model.setType(random.nextInt(2));
//                    model.setScope("软装 硬装");
//                    model.setId(integer.toString());
//                    return model;
//                })
//                .toList()
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(rs -> parserData(isLoadMore, rs)));
    }


    /**
     * 选择地区
     */
    public void areaClicked(View view) {
        mView.conditionSelector(C_AREA);
    }

    /**
     * 设计师类型选择
     *
     * @param view
     */
    public void typeClicked(View view) {
        mView.conditionSelector(C_TYPE);
    }

    /**
     * 设计报价选择
     */
    public void priceClicked(View view) {
        mView.conditionSelector(C_PRICE);
    }

    /**
     * 综合排序
     */
    public void allClicked(View view) {
        mView.conditionSelector(C_ALL);
    }


    @IntDef(value = {
            C_AREA, C_TYPE, C_PRICE, C_ALL
    })

    @Retention(RetentionPolicy.SOURCE)
    public @interface DesignerCondition {
    }

}